package com.zgjkhis.modules.system.domain;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.zgjkhis.modules.charges.domain.PrescriptionOrder;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * @Author yzq
 * @Description 订单
 * @Date 2021/6/23 9:38
 * @Param
 * @return
 **/
@Data
@TableName("his_prescription_order")
public class Order implements Serializable {

    @TableId
    private Long id;
    @ApiModelProperty(value = "订单编码",required = true)
    private String orderNo;
    @ApiModelProperty(value = "医生名称",required = true)
    private String docName;
    @ApiModelProperty(value = "医生id",required = true)
    private String docId;
    @ApiModelProperty(value = "患者名称",required = true)
    private String patientName;
    @ApiModelProperty(value = "患者id",required = true)
    private String patientId;
    @ApiModelProperty(value = "患者性别1-男，2-女",required = true)
    private Integer patientSex;
    @ApiModelProperty(value = "患者年龄",required = true)
    private String patientAge;
    @ApiModelProperty(value = "物流商编号",required = true)
    private String expressCode;
    @ApiModelProperty(value = "1 邮寄 2 自提",required = true)
    private Integer deliveryType;
    @ApiModelProperty(value = "总金额",required = true)
    private BigDecimal totalFee;
    @ApiModelProperty(value = "加工费",required = true)
    private BigDecimal machinFee;
    @ApiModelProperty(value = "快递费",required = true)
    private BigDecimal expressFee;
    @ApiModelProperty(value = "支付状态 0：待收费，1:已收费(待审方)，2：调剂中，3：部分退费，4：已退费，5：待发货（已调剂） 6已完成（已收货）",required = true)
    private Integer payStatus;
    @ApiModelProperty(value = "订单状态，1：已收费(待审方)，2：调剂中(已审核)，3：待发货",required = true)
    private Integer orderCondition;
    @ApiModelProperty(value = "是否有效：0：是，1：否",required = true)
    private Integer orderStatus;
    @ApiModelProperty(value = "订单类型：1：本地处方，2：云享处方",required = true)
    private Integer orderType;
    @ApiModelProperty(value = "药房id",required = true)
    private String consultNo;
    /** 创建时间 */
    @TableField(fill= FieldFill.INSERT)
    @ApiModelProperty(value = "创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    private Date orderTime;
    @ApiModelProperty(value = "问诊号",required = true)
    private String pharmacyId;
    @ApiModelProperty(value = "云享处方订单号")
    private String apiOrderNo;
    @ApiModelProperty(value = "部门名称")
    private String departmentName;
    @ApiModelProperty(value = "部门id")
    private String departmentId;
    @ApiModelProperty(value = "订单来源")
    private String source;
    @ApiModelProperty(value = "订单来源渠道id")
    private String sourceId;
    @ApiModelProperty(value = "备注")
    private String remark;
    @ApiModelProperty(value = "支付时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    private Date payTime;
    @ApiModelProperty(value = "药费")
    private BigDecimal drugCost;
    @ApiModelProperty(value = "附加费用")
    private BigDecimal otherCost;
    @ApiModelProperty(value = "订单来源门店id")
    private String sourceStoreId;
    @ApiModelProperty(value = "订单来源门店名称")
    private String sourceStoreName;
    @ApiModelProperty(value = "审方人id")
    private String checkUserId;
    @ApiModelProperty(value = "审方人名称")
    private String checkUser;
    @ApiModelProperty(value = "审方时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    private Date checkTime;
    @ApiModelProperty(value = "调剂用户id")
    private String adjustUserId;
    @ApiModelProperty(value = "调剂用户")
    private String adjustUser;
    @ApiModelProperty(value = "调剂时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    private Date adjustTime;
    @TableField(fill= FieldFill.INSERT)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    @ApiModelProperty(value = "创建时间")
    private Date createTime;
    @ApiModelProperty(value = "费用减免")
    private BigDecimal diffFee;
    @ApiModelProperty(value = "药费折扣")
    private BigDecimal drugDiscount;
    @ApiModelProperty(value = "整体折扣")
    private BigDecimal allDiscount;
    @ApiModelProperty(value = "其他费用")
    private BigDecimal otherFee;
    @ApiModelProperty(value = "支付方式，1：现金，2：微信，3：支付宝，4：银行卡，5：医保")
    private Integer payWay;
    @ApiModelProperty(value = "实际收费")
    private BigDecimal actualCharge;
    @ApiModelProperty(value = "流转金额")
    private BigDecimal cirulationCost;
    @ApiModelProperty(value = "流转订单号")
    private String cirOrderNo;
    @ApiModelProperty(value = "流转处方号")
    private String cirInfoNo;

    @ApiModelProperty(value = "确认收货用户id")
    private String receiptUserId;
    @ApiModelProperty(value = "确认收货用户名称")
    private String receiptUser;
    @ApiModelProperty(value = "确认收货时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    private Date receiptUserTime;
    @ApiModelProperty(value = "下次发货时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    private Date nextTime;
    @ApiModelProperty(value = "下次发货原因")
    private String nextRemark;
    @ApiModelProperty(value = "1:已处理，2：未处理")
    private Integer nextFlag;
    @ApiModelProperty(value = "退款是否处理 1：未处理，2：已处理")
    private Integer refundFlag;
    @ApiModelProperty(value = "补发订单的原订单号")
    private String oldOrderNo;
    @ApiModelProperty(value = "补发原因")
    private String reissueReason;
    @ApiModelProperty(value = "退款库存方式，0：报损，1：退库存，2：未调剂不推库存")
    private String refundType;

    @ApiModelProperty(value = "处方列表")
    @TableField(exist = false)
    private List<Info> infos;

    public void copy(Order source){
        BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
    }

    public PrescriptionOrder copyOrder(String orderNo,PrescriptionOrder source){
        PrescriptionOrder tempOrder=new PrescriptionOrder();
        BeanUtils.copyProperties(source,tempOrder);
        tempOrder.setId(null);
        tempOrder.setOrderNo(orderNo);
        tempOrder.setOrderTime(new Date());
        tempOrder.setCreateTime(new Date());
        tempOrder.setTotalFee(BigDecimal.ZERO);
        tempOrder.setMachinFee(BigDecimal.ZERO);
        tempOrder.setExpressFee(BigDecimal.ZERO);
        tempOrder.setPayStatus(1);
        tempOrder.setOrderStatus(0);
        tempOrder.setPayTime(new Date());
        tempOrder.setOtherCost(BigDecimal.ZERO);
        tempOrder.setDrugCost(BigDecimal.ZERO);
        tempOrder.setOrderCondition(1);
        tempOrder.setCheckUserId(null);
        tempOrder.setCheckUser(null);
        tempOrder.setCheckTime(null);
        tempOrder.setAdjustTime(null);
        tempOrder.setAdjustUser(null);
        tempOrder.setAdjustUserId(null);
        tempOrder.setDiffFee(BigDecimal.ZERO);
        tempOrder.setDrugCost(BigDecimal.ZERO);
        tempOrder.setAllDiscount(BigDecimal.ZERO);
        tempOrder.setReceiptUserTime(null);
        tempOrder.setReceiptUser(null);
        tempOrder.setReceiptUserId(null);
        tempOrder.setCirulationCost(BigDecimal.ZERO);
        tempOrder.setCirOrderNo(null);
        tempOrder.setCirInfoNo(null);
        tempOrder.setNextTime(null);
        tempOrder.setNextRemark(null);
        tempOrder.setRefundFlag(null);
        tempOrder.setNextFlag(1);
        tempOrder.setOldOrderNo(source.getOrderNo());
        return tempOrder;
    }
}
